package servlet;

import model.UserInfo;
import service.UseInfoService;
import utils.MyBatisUtil;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

import static java.lang.Thread.sleep;

@WebServlet(name = "InsertUseInfoServlet", value = "/InsertUseInfoServlet")
public class InsertUseInfoServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        UseInfoService uis = new UseInfoService();
        UserInfo ui = new UserInfo();
        if (request.getParameter("username") != null)
            ui.setUserName(request.getParameter("username"));
        if (request.getParameter("usersex") != null)
            ui.setUserSex(request.getParameter("usersex"));
        if (request.getParameter("userpass") != null)
            ui.setUserPass(request.getParameter("userpass"));
        if (request.getParameter("userage") != null)
            ui.setUserAge(Integer.valueOf(request.getParameter("userage")));
        int i = uis.insertUser(ui);

        MyBatisUtil.closeSession();
        request.getRequestDispatcher("/SelectAllServlet").forward(request, response);
    }
}
